/*
 * Created on Oct 10, 2004
 */
package org.vectrics.history.hibernate;

import java.sql.Connection;

import org.hibernate.CallbackException;
import org.hibernate.Session;
import org.vectrics.common.db.Auditable;
import org.vectrics.config.ApplicationConfiguration;
import org.vectrics.hibernate.ThreadProperties;
import org.vectrics.hibernate.HibernateUtil;
import org.vectrics.hibernate.TransactionToken;
import org.vectrics.history.AuditLogRecord;
import org.vectrics.provider.CoreServiceLocator;

/**
 * @author mmoore
 */
public class AuditLog {
	public static void logEvent(String message, Auditable entity, Long personId, HibernateUtil hibernate, Connection connection) {
		TransactionToken txToken = ThreadProperties.beginTransaction();
		ThreadProperties.setPerson(CoreServiceLocator.getConfiguration().getSystemPerson());
		AuditLogRecord record = new AuditLogRecord(message, entity.getId(), entity.getClass(), personId);
		ThreadProperties.getSession().save(record);
		ThreadProperties.commitTransaction(txToken);
		ThreadProperties.getSession().flush();
	}
	
}
